Create examples for HardwareTimer library #12
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Examples
Following examples are provided in STM32Examples library (available with Arduino Library manager).
Requirement: HardwareTimer library
Timebase_callback.ino
This example shows how to configure HardwareTimer to execute a callback at regular interval.
Callback toggles pin.
Once configured, there is only CPU load for callbacks executions.
PWM_FullConfiguration.ino
This example shows how to fully configure a PWM with HardwareTimer.
PWM is generated on
LED_BUILTIN
if available.PWM is generated by hardware: no CPU load.
Nevertheless, in this example both interruption callback are used on Compare match (Falling edge of PWM1 mode) and update event (rising edge of PWM1 mode).
Those call back are used to toggle a second pin:
pin2
.Once configured, there is only CPU load for callbacks executions.
All-in-one_setPWM.ino
This example shows how to configure a PWM with HardwareTimer in one single function call.
PWM is generated on
LED_BUILTIN
if available.No interruption callback used: PWM is generated by hardware.
Once configured, there is no CPU load.
InputCapture.ino
This example shows how to configure HardwareTimer in inputcapture to measure external signal frequency.
Each time a rising edge is detected on the input pin, hardware will save counter value into CaptureCompare register.
External signal (signal generator for example) should be connected to
D2
.Measured frequency is displayed on Serial Monitor.
Frequency_Dutycycle_measurement.ino
This example shows how to configure HardwareTimer to measure external signal frequency and dutycycle.
The input pin will be connected to 2 channel of the timer, one for rising edge the other for falling edge.
Each time a rising edge is detected on the input pin, hardware will save counter value into one of the CaptureCompare register.
Each time a falling edge is detected on the input pin, hardware will save counter value into the other CaptureCompare register.
External signal (signal generator for example) should be connected to
D2
.